﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Entity;

namespace SetListManager.Models
{

     //***********************************************************************************
     // NOTE: This code will fail once we move it to our shared hosting provider, Arvixe.  
     // This code will drop then re-create the database on our server, which works locally.
     // However once we place this onto our shared server, the server does not allow 
     // DB drop/create operations from code, it must be done using the Arvixe control panel.
     //***********************************************************************************

    /// <summary>
    /// Initializes a test database for the Song model
    /// </summary>
    public class SLMDbInitializer : DropCreateDatabaseIfModelChanges<SLMDbContext>
    {
        protected override void Seed(SLMDbContext context)
        {
            // ************************************************************
            // Create a few "Usage Types"
            // ************************************************************
            var usagetypes = new List<UsageType> {
                new UsageType {UsageTypeID=1, UsageText="Current", BandID=1},
                new UsageType {UsageTypeID=2, UsageText="Ocassional", BandID=1 },
                new UsageType {UsageTypeID=3, UsageText="No Longer Used", BandID=1 },
                new UsageType {UsageTypeID=4, UsageText="Christmas", BandID=1 }
            };
            usagetypes.ForEach(u => context.UsageTypes.Add(u));

            // ************************************************************
            // Fill out some test bands
            // ************************************************************
            var bands = new List<Band> {
                new Band { Name = "The Castaways Band", BandID=1, 
                    Note1IsColumn=false, Note1Name="General Note",
                    Note2IsColumn=true, Note2Name="Who Starts?",
                    Note3IsColumn=true, Note3Name="Keyboard",
                    Note4IsColumn=true, Note4Name="Guitar",
                    Note5IsColumn=false, Note5Name="Drummer Notes"},
                new Band { Name = "Mixology", BandID=2,
                    Note1IsColumn=false, Note1Name="General Note",
                    Note2IsColumn=true, Note2Name="Prop",
                    Note3IsColumn=true, Note3Name="Dancer Cue",
                    Note4IsColumn=true, Note4Name="Guitar Patch",
                    Note5IsColumn=true, Note5Name="Light Cue"}
            };
            bands.ForEach(b => context.Bands.Add(b));

            // ************************************************************
            // Create song groups
            // ************************************************************
            var groups = new List<SongGroup> {
                new SongGroup { GroupID=1,
                    Name="Billy Jean / Mama Say"},
                new SongGroup { GroupID=2,
                    Name="Raise Your Glass / I Love RnR / Brick House"}
            };

            // ************************************************************
            // Fill out some test songs
            // ************************************************************
            var songs = new List<Song> {   
   
                 new Song { Title = "Freeze Frame",    
                     Key = "C",
                     Soloist = "Natalie",
                     Tempo = "120",
                     Duration = new MinSec(2,40),
                     Usage = usagetypes.Find(u => u.UsageTypeID == 1),
                     Note1 = "Starts on the 5, vamps on the 1",
                     Note2 = "Drums",
                     Note3 = "45",
                     Band = bands.Find(b => b.BandID == 1),
                     Group = null,
                     SongID = 1
                 },

                 new Song { Title = "Mustang Sally",    
                     Key = "E",
                     Soloist = "Will",
                     Tempo = "140",
                     Duration = new MinSec(3,20),
                     Usage = usagetypes.Find(u => u.UsageTypeID == 1),
                     Note1 = "Intro-V-C-V-C-Solo-Outro",
                     Note5 = "Drums start song, on 4&.  Structure: Intro-V-C-V-C-Solo-Outro.",
                     Band = bands.Find(b => b.BandID == 1),
                     Group = null,
                     SongID = 2

                },

                 new Song { Title = "Take me to the River",    
                     Key = "Am",
                     Soloist = "Stephen",
                     Tempo = "80",
                     Duration = new MinSec(3,0),
                     Usage = usagetypes.Find(u => u.UsageTypeID == 1),
                     // No Note1 for this song
                     Band = bands.Find(b => b.BandID == 1),
                     Group = null,
                     SongID = 3
                },

                new Song { Title = "Beat It",    
                     Key = "Gm",
                     Soloist = "Michael",
                     Tempo = "82",
                     Duration = new MinSec(3,22),
                     Usage = usagetypes.Find(u => u.UsageTypeID == 1),
                     // No Note1 for this song
                     Band = bands.Find(b => b.BandID == 1),
                     Group = groups.Find(g => g.GroupID == 1),
                     GroupOrder = 1,
                     SongID = 4
                },
                new Song { Title = "Mama Say Mama Saw Mama Coo Saw",    
                     Key = "Am",
                     Soloist = "Michael",
                     Tempo = "105",
                     Duration = new MinSec(2,15),
                     Usage = usagetypes.Find(u => u.UsageTypeID == 1),
                     // No note for this song
                     Band = bands.Find(b => b.BandID == 1),
                     Group = groups.Find(g => g.GroupID == 1),
                     GroupOrder = 2,
                     SongID = 5
                },
                new Song { Title = "Raise Your Glass",    
                     Key = "E",
                     Soloist = "Smitty",
                     Tempo = "100",
                     Duration = new MinSec(4,5),
                     Usage = usagetypes.Find(u => u.UsageTypeID == 1),
                     // No note for this song
                     Band = bands.Find(b => b.BandID == 1),
                     Group = groups.Find(g => g.GroupID == 2),
                     GroupOrder = 1,
                     SongID = 6
                },
                new Song { Title = "I Love Rock n Roll (Joan Jett/Queen)",    
                     Key = "E",
                     Soloist = "Natalie",
                     Tempo = "70",
                     Duration = new MinSec(2,0),
                     Usage = usagetypes.Find(u => u.UsageTypeID == 1),
                     // No note for this song
                     Band = bands.Find(b => b.BandID == 1),
                     Group = groups.Find(g => g.GroupID == 2),
                     GroupOrder = 2,
                     SongID = 7
                },
                new Song { Title = "Brick House",    
                     Key = "Am",
                     Soloist = "Natalie",
                     Tempo = "82",
                     Duration = new MinSec(3,25),
                     Usage = usagetypes.Find(u => u.UsageTypeID == 1),
                     // No note for this song
                     Band = bands.Find(b => b.BandID == 1),
                     Group = groups.Find(g => g.GroupID == 2),
                     GroupOrder = 3,
                     SongID = 8
                },
                new Song { Title = "Crazy Train",    
                     Key = "Dm",
                     Soloist = "Jim",
                     Duration = new MinSec(2,48),
                     Usage = usagetypes.Find(u => u.UsageTypeID == 1),
                     // No note for this song
                     Band = bands.Find(b => b.BandID == 1),
                     Group = null,
                     SongID = 9
                },
                new Song { Title = "Deadly Handsome Man",    
                     Key = "G",
                     Soloist = "Jim",
                     Duration = new MinSec(3,0),
                     Usage = usagetypes.Find(u => u.UsageTypeID == 1),
                     // No note for this song
                     Band = bands.Find(b => b.BandID == 1),
                     SongID = 10
                },
                new Song { Title = "Hungry like the Wolf",    
                     Key = "A",
                     Soloist = "Ed",
                     Duration = new MinSec(4,0),
                     Usage = usagetypes.Find(u => u.UsageTypeID == 1),
                     // No note for this song
                     Band = bands.Find(b => b.BandID == 1),
                     SongID = 11
                },
                new Song { Title = "Stray Cat Strut",    
                     Key = "Cm",
                     Soloist = "Ed",
                     Tempo = "100",
                     Duration = new MinSec(2,45),
                     Usage = usagetypes.Find(u => u.UsageTypeID == 1),
                     Note1 = "Starts out with snare and bass",
                     Band = bands.Find(b => b.BandID == 1),
                     SongID = 12
                },
                new Song { Title = "All You Need is Love (Beatles)",    
                     Key = "F",
                     Soloist = "Jim",
                     Tempo = "80",
                     Duration = new MinSec(3,25),
                     Usage = usagetypes.Find(u => u.UsageTypeID == 1),
                     Band = bands.Find(b => b.BandID == 1),
                     SongID = 13
                },
                new Song { Title = "Paint It Black",    
                     Key = "Dm",
                     Soloist = "Mark",
                     Tempo = "120",
                     Duration = new MinSec(4,45),
                     Usage = usagetypes.Find(u => u.UsageTypeID == 1),
                     Band = bands.Find(b => b.BandID == 1),
                     SongID = 14
                },
                new Song { Title = "Time Warp",    
                     Key = "A",
                     Soloist = "All",
                     Tempo = "160",
                     Duration = new MinSec(3,50),
                     Usage = usagetypes.Find(u => u.UsageTypeID == 1),
                     Band = bands.Find(b => b.BandID == 1),
                     SongID = 15
                },
                new Song { Title = "Working for the Weekend",    
                     Key = "A",
                     Soloist = "Pete",
                     Tempo = "120",
                     Duration = new MinSec(3,25),
                     Usage = usagetypes.Find(u => u.UsageTypeID == 1),
                     Band = bands.Find(b => b.BandID == 1),
                     SongID = 16
                },
                new Song { Title = "Soul Man",    
                     Key = "Bb",
                     Soloist = "Jim",
                     Tempo = "90",
                     Duration = new MinSec(4,10),
                     Usage = usagetypes.Find(u => u.UsageTypeID == 1),
                     Band = bands.Find(b => b.BandID == 1),
                     SongID = 17
                },
                new Song { Title = "Maneater (Oh oh here she comes)",    
                     Key = "Am",
                     Soloist = "Jim",
                     Tempo = "70",
                     Duration = new MinSec(2,0),
                     Usage = usagetypes.Find(u => u.UsageTypeID == 1),
                     Band = bands.Find(b => b.BandID == 1),
                     SongID = 18
                },
                new Song { Title = "Istanbul not Constantinople",
                     Key = "Fm",
                     Soloist = "Mark",
                     Tempo = "60",
                     Duration = new MinSec(4,15),
                     Usage = usagetypes.Find(u => u.UsageTypeID == 1),
                     Band = bands.Find(b => b.BandID == 1),
                     SongID = 19
                },
                new Song { Title = "Keep Feeling Fascination",    
                     Key = "C",
                     Soloist = "Pete",
                     Tempo = "110",
                     Duration = new MinSec(3,50),
                     Usage = usagetypes.Find(u => u.UsageTypeID == 1),
                     Band = bands.Find(b => b.BandID == 1),
                     SongID = 20
                },
                new Song { Title = "Mama Told Me Not To Come",    
                     Key = "E",
                     Soloist = "Natalie",
                     Tempo = "70",
                     Duration = new MinSec(2,0),
                     Usage = usagetypes.Find(u => u.UsageTypeID == 1),
                     Band = bands.Find(b => b.BandID == 1),
                     SongID = 21
                },
                new Song { Title = "Spirits in the Material World",
                     Key = "E",
                     Soloist = "Jim",
                     Tempo = "70",
                     Duration = new MinSec(4,0),
                     Usage = usagetypes.Find(u => u.UsageTypeID == 1),
                     Band = bands.Find(b => b.BandID == 1),
                     SongID = 22
                }
             };

            songs.ForEach(d => context.Songs.Add(d));

            // ************************************************************
            // Create a few set lists
            // ************************************************************
            var setlists = new List<SetList>
            {
                new SetList { 
                    SetListID=1,
                    BandID=1,
                    Name = "The Shanty", 
                    GigDate = new DateTime(2011, 03, 24),
                    GigTime = new TimeSpan(14, 30, 0),
                    SetDuration = new MinSec(135, 24),
                    Items = new List<SetListItem> {
                        new SetListItem {
                            SetNumber = 1,
                            Note="Band vamp to start set",
                            SongOrder = 1
                        },
                        new SetListItem {
                            SetNumber = 1,
                            Song = songs.Find(s => s.SongID == 2),
                            SongOrder = 2
                        },
                        new SetListItem {
                            SetNumber = 1,
                            Song = songs.Find(s => s.SongID == 1),
                            SongOrder = 3
                        },
                        new SetListItem {
                            SetNumber = 2,
                            Song = songs.Find(s => s.SongID == 3),
                            SongOrder = 1
                        },
                        new SetListItem {
                            SetNumber = 2,
                            Song = songs.Find(s => s.SongID == 4),
                            SongOrder = 2
                        }
                    }
                },

                new SetList { 
                    SetListID=2,
                    BandID=1,
                    Name = "Four Winds Casino (Marysville)", 
                    GigDate = new DateTime(2011, 04, 16),
                    GigTime = new TimeSpan(18, 0, 0),
                    SetDuration = new MinSec(188, 0),
                    Items = new List<SetListItem> {
                        new SetListItem {
                            SetNumber = 1,
                            Song = songs.Find(s => s.SongID == 7),
                            SongOrder = 1
                        },
                        new SetListItem {
                            SetNumber = 1,
                            Note = "Go right on to...",
                            SongOrder = 2
                        },
                        new SetListItem {
                            SetNumber = 1,
                            Song = songs.Find(s => s.SongID == 5),
                            SongOrder = 3
                        },
                        new SetListItem {
                            SetNumber = 2,
                            Song = songs.Find(s => s.SongID == 2),
                            SongOrder = 3
                        },
                        new SetListItem {
                            SetNumber = 2,
                            Song = songs.Find(s => s.SongID == 1),
                            SongOrder = 4
                        },
                        new SetListItem {
                            SetNumber = 2,
                            Song = songs.Find(s => s.SongID == 3),
                            SongOrder = 5
                        },

                        new SetListItem {
                            SetNumber = 2,
                            Song = songs.Find(s => s.SongID == 4),
                            SongOrder = 6
                        },
                        new SetListItem {
                            SetNumber = 2,
                            Note = "Keep last song going, singers leave stage.",
                            SongOrder = 7
                        }
                    }
                }

            };
            setlists.ForEach(s => context.SetLists.Add(s));

            // ************************************************************
            // Save changes
            // ************************************************************
            context.SaveChanges();
        }
    }

}
